package com.example.controller;

import com.example.entity.Order;
import com.example.service.OrderService;
import com.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/createOrder")
    public Result createOrder(String userId, Integer shopId) {
        Integer orderId = orderService.createOrder(userId, shopId);
        return Result.ok(orderId);
    }

    @PostMapping("/getOrderById")
    public Result getOrderById(Integer orderId) {
        Order order = orderService.getOrderById(orderId);
        return Result.ok(order);
    }

    @PostMapping("/pay")
    public Result payOrder(Integer orderId) {
        orderService.payOrder(orderId);
        return Result.ok();
    }

    @PostMapping("/listOrderByUserId")
    public Result listOrderByUserId(String userId) {
        List<Order> order = orderService.listOrderByUserId(userId);
        return Result.ok(order);
    }

}
